Repository navigation
gh-162010: Drop pending literal on rejected imaplib.APPEND commands - #162017
Open
jhaabhijeet864 wants to merge 1 commit into
Open
jhaabhijeet864 wants to merge 1 commit into
jhaabhijeet864 wants to merge 1 commit into
Conversation
…ands
When IMAP4.append() is called, it stores the message payload in self.literal and calls _command('APPEND', ...). Following pythongh-143921 (CVE-2025-15366), if any argument contains control characters (NUL, CR, or LF), _command() raises ValueError before popping and clearing self.literal. This left self.literal pending on the client instance, attaching itself as an unexpected literal to whatever command was executed next (such as NOOP).
Ingest and clear self.literal into local scope at the start of _command(), guaranteeing that any exception occurring prior to transmission drops the literal immediately and prevents session corruption or data leakage.
jhaabhijeet864
force-pushed
the
gh-162010
branch
from
November 15, 2026 06:00
629ac73 to
aaf2547
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #162010. Follow-up to gh-143921 / CVE-2025-15366.
Problem
When
IMAP4.append()is invoked, it stores the message payload inself.literalbefore calling_command('APPEND', ...). If an argument contains control characters (such as NUL, CR, or LF),_command()raises aValueError("NUL, CR and LF not allowed in commands")while building the command line.Because this check happens before
self.literalis ingested and cleared,self.literalremained pending on the instance. When the caller subsequently issues any other command (e.g.,noop()),_command()attaches the leftover literal to that command. The server unexpectedly receivesNOOP {size}followed by the message bytes, leading to client connection abortion and unintended transmission of aborted message data.Solution
Ingest and clear
self.literalinto local scope at the start of_command(). This ensures that any validation failure or exception occurring prior to transmission unconditionally clearsself.literaland prevents literal state leakage across commands.Testing
test_control_characters_append_literalinLib/test/test_imaplib.py.test_imaplibtest suite (268 passed, 0 failures).